package com.example.demo.service;

import com.example.demo.entity.Articleinfo;
import com.example.demo.entity.CheckArticleinfo;
import com.example.demo.entity.DelArticleinfo;
import com.example.demo.entity.HistoryNotiinfo;
import com.example.demo.mapper.ArticleMapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class ArticleService {

    @Resource
    private ArticleMapper articleMapper;

    // 根据id 查询文章数量
    public int getArtCountByUid(Integer uid){
        return articleMapper.getArtCountByUid(uid);
    }

    //查询文章列表
    public List<Articleinfo> getMyList(Integer uid){
        return articleMapper.getMyList(uid);
    }

    //删除文章
    public int del(Integer id ,Integer uid){
        return articleMapper.del(id,uid);
    }


    //查询文章详情
    public Articleinfo getDetail(Integer id){
        return articleMapper.getDetail(id);
    }

    //文章阅读量+1
    public int incrRCount(Integer id){
        return articleMapper.incrRCount(id);
    }


    //添加文章
    public int add(Articleinfo articleinfo){
       return articleMapper.add(articleinfo);
    }


    //修改文章
    public int update(Articleinfo articleinfo){
        return articleMapper.update(articleinfo);
    }


    //获取文字列表，分页
    public List<Articleinfo> getListByPage(Integer psize,Integer offsize){
        return articleMapper.getListByPage(psize,offsize);
    }


    //获取文章总条数
    public int getCount(){
        return articleMapper.getCount();
    }

    //向数据库中存储草稿
    public int addDraft(Articleinfo articleinfo){
        return articleMapper.addDraft(articleinfo);
    }

    //获取当前用户的草稿并展示
    public List<Articleinfo> getMyDraft(Integer id){
        return articleMapper.getMyDraft(id);
    }

    //删除草稿
    public int delDraft(Integer id,Integer uid){
        return articleMapper.delDraft(id,uid);
    }
    //根据草稿id查询对应草稿
    public Articleinfo getDraftById(Integer id){
        return articleMapper.getDraftById(id);
    }

    //修改草稿
    public int updateDraft(Articleinfo articleinfo){
        return articleMapper.updateDraft(articleinfo);
    }

    //显示草稿全文
    public Articleinfo getDraftDetail(int id){
        return articleMapper.getDraftDetail(id);
    }

    //查询草稿左侧个人信息
    public int getDraftCountByUid(Integer uid){
        return articleMapper.getDraftCountByUid(uid);
    }

    //根据aid在文章表里面找到对应的uid
    public int getUidByAid(Integer aid) {
        return articleMapper.getUidByAid(aid);
    }


    //文章赞加一
    public int updateGCount(Integer id) {
        return articleMapper.updateGCount(id);
    }

    //文章踩加一
    public int updateBCount(Integer id) {
        return articleMapper.updateBCount(id);
    }





    //管理员删除文章
    public int deleteById(Integer id){
        return articleMapper.deleteById(id);
    }


    //根据文章id获取文章信息
    public Articleinfo getArticleById(Integer id) {
        return articleMapper.getArticleById(id);
    }

    //将删除文章的信息保存到 delarticle 表中
    public int saveDelArticle(DelArticleinfo delArticleinfo) {
        return articleMapper.saveDelArticle(delArticleinfo);
    }

    //查询用户被管理员删除的文章
    public List<DelArticleinfo> getAllDelArticleByUId(int uid) {
        return articleMapper.getAllDelArticleByUid(uid);
    }

    //修改要删除的文章id为i
    public int updateState(Integer id, int i) {
        return articleMapper.updateState(id,i);
    }

    //删除当前用户的被管理员删除文章的通知信息
    public int updateDelArticleState(int uid) {
        return articleMapper.updateDelArticleState(uid);
    }

    //删除单条被管理员删除文章的通知
    public int deleteDelNotiByAid(Integer aid) {
        return articleMapper.deleteDelNotiByAid(aid);
    }

    //获取历史通知
    public List<HistoryNotiinfo> getHistoryNoti(int uid) {
        return articleMapper.getHistoryNoti(uid);
    }

    //获取所有待审核的文章
    public List<Articleinfo> getAllCheckArticle() {
        return articleMapper.getAllCheckArticle();
    }

    //向checkArticle表中插入审核文章的信息
    public int insertCheckArticle(CheckArticleinfo checkArticleinfo) {
        return articleMapper.insertCheckArticle(checkArticleinfo);
    }

    //获取CheckArticle中本用户的所有通知信息
    public List<CheckArticleinfo> getAllCheckArticleInCheckArticle(int uid) {
        return articleMapper.getAllCheckArticleInCheckArticle(uid);
    }

    //将checkarticle表中的aid数据的state改为3
    public int updateCheckeNotiByAid(Integer aid,Integer state) {
        return articleMapper.updateCheckeNotiByAid(aid,state);
    }

    //将删除的通知存入historynoti表中
    public int insertHistoryToHistoryNoti(HistoryNotiinfo historyNotiinfo) {
        return articleMapper.insertHistoryToHistoryNoti(historyNotiinfo);
    }

    //根据aid获取此条记录的时间
    public LocalDateTime getDelTimeArticleByAid(Integer aid) {
        return articleMapper.getDelTimeArticleByAid(aid);
    }

    //根据aid在checkarticle中获取时间
    public LocalDateTime getDelTimeInCheckArticleByAid(Integer aid) {
        return articleMapper.getDelTimeInCheckArticleByAid(aid);
    }

    //将checkarticle中的state为1 2的数据的state统一加2
    public int updateAllCheckArticleStateAddTwo(int uid) {
        return articleMapper.updateAllCheckArticleStateAddTwo(uid);
    }
}















